package core.dal;

import java.util.ArrayList;

import utilities.PasswordGenerator;
import core.dto.IDatabase;
import core.dto.IOperatorDTO;
import core.dto.OperatorDTO;
import exceptions.UserNotFoundException;

public class AdminFunctionality implements IFunctionality{
	

	

		
	private PasswordGenerator pG = new PasswordGenerator();
	private IDatabase currentDB;
	
	public AdminFunctionality(IDatabase currentDB){
		this.currentDB = currentDB;
	}

	public void createUser(String navn, String cpr)throws UserNotFoundException{
		IOperatorDTO tempUser = new OperatorDTO();
		tempUser.setCpr(cpr);
		tempUser.setOprNavn(navn);
		tempUser.setOprId((int) (Math.floor((Math.random() * 88) + 11)));
		tempUser.setPassword(pG.getNewPassword());
		this.currentDB.add(tempUser);

	}
	
	public void deleteUser(int id) throws UserNotFoundException{
		this.currentDB.remove(id);
	}
	
	public void editUser(int id, String navn, String password, String cpr) throws UserNotFoundException{
		IOperatorDTO tempUser = this.currentDB.getUser(id);
		tempUser.setCpr(cpr);
		tempUser.setOprNavn(navn);
		tempUser.setPassword(password);
	}
	
	public IOperatorDTO showUser(int id) throws UserNotFoundException{
		return this.currentDB.getUser(id);
	}
	
	public ArrayList<IOperatorDTO> showUsers(){
		return (ArrayList<IOperatorDTO>)this.currentDB.getUserList();
		
	}
	public static void main(String[] args) {
	}
}
